import { _local } from '@/utils/storage'
import { ACCESS_TOKEN, RY_TOKEN, RY_ID, SECRET, USER_ID, INITIALIZE, LOCATION_PERMISSIONS, STORAGE_PERMISSIONS, IP_ADDRESS, PRIVACY, GEOLOCATION, LOGIN_STATUS, CHOOSE_CITY, CHOOSE_CITY_QUALIFY, POSITION } from '@/construct/setting'
import { HOUSE_LIST, HOUSE_LIST_BUY, HOUSE_LIST_NEW } from '@/construct/const'
import { baseUtils } from './baseUtils'

export function getInitialize() {
  const res = _local.get(INITIALIZE)
  if (parseInt(res) === 1) {
    return true
  } else {
    return false
  }
}

export function setInitialize(initialize) {
  return _local.set(INITIALIZE, initialize)
}

export function removeInitialize() {
  return _local.remove(INITIALIZE)
}

export function getLoginStatus() {
  const status = _local.get(LOGIN_STATUS)
  // 1 登录成功
  if (parseInt(status) === 1) {
    return true
  } else {
    return false
  }
}

export function setLoginStatus(status) {
  return _local.set(LOGIN_STATUS, status)
}

export function removeLoginStatus() {
  return _local.remove(LOGIN_STATUS)
}

export function getStoragePermissions() {
  const res = _local.get(STORAGE_PERMISSIONS)
  if (parseInt(res) === 1) {
    return false
  } else {
    return true
  }
}

export function setStoragePermissions(storagePermissions) {
  return _local.set(STORAGE_PERMISSIONS, storagePermissions)
}

export function removeStoragePermissions() {
  return _local.remove(STORAGE_PERMISSIONS)
}

export function getToken() {
  const res = _local.get(ACCESS_TOKEN)
  return baseUtils.isEmpty(res) ? '' : res
}

export function setToken(token) {
  return _local.set(ACCESS_TOKEN, token)
}

export function removeToken() {
  return _local.remove(ACCESS_TOKEN)
}

// 保存融云令牌
export function setRyToken(ryToken) {
  return _local.set(RY_TOKEN, ryToken)
}

// 获取融云令牌
export function getRyToken() {
  const res = _local.get(RY_TOKEN)
  return baseUtils.isEmpty(res) ? '' : res
}

// 删除 ry token
export function removeRyToken() {
  return _local.remove(RY_TOKEN)
}

// 保存融云令牌
export function setUserId(userId) {
  return _local.set(USER_ID, userId)
}

// 获取融云令牌
export function getUserId() {
  const res = _local.get(USER_ID)
  return baseUtils.isEmpty(res) ? '' : res
}

// 删除 ry token
export function removeUserId() {
  return _local.remove(USER_ID)
}

// 保存融云令牌
export function setRyId(ryId) {
  return _local.set(RY_ID, ryId)
}

// 获取融云令牌
export function getRyId() {
  const res = _local.get(RY_ID)
  return baseUtils.isEmpty(res) ? '' : res
}

// 删除 ry token
export function removeRyId() {
  return _local.remove(RY_ID)
}

export function setHouseList(data) {
  return _local.set(HOUSE_LIST, data)
}

export function getHouseList() {
  const res = _local.get(HOUSE_LIST)
  return baseUtils.isEmpty(res) ? [] : res
}

export function removeHouseList() {
  return _local.remove(HOUSE_LIST)
}

export function setHouseListBuy(data) {
  return _local.set(HOUSE_LIST_BUY, data)
}

export function getHouseListBuy() {
  const res = _local.get(HOUSE_LIST_BUY)
  return baseUtils.isEmpty(res) ? [] : res
}

export function removeHouseListBuy() {
  return _local.remove(HOUSE_LIST_NEW)
}

export function setHouseListNew(data) {
  return _local.set(HOUSE_LIST_NEW, data)
}

export function getHouseListNew() {
  const res = _local.get(HOUSE_LIST_NEW)
  return baseUtils.isEmpty(res) ? [] : res
}

export function removeHouseListNew() {
  return _local.remove(HOUSE_LIST_NEW)
}

export function setSecret(data) {
  return _local.set(SECRET, data)
}

export function getSecret() {
  return _local.get(SECRET)
}

export function removeSecret() {
  return _local.remove(SECRET)
}

export function getIp() {
  return _local.get(IP_ADDRESS)
}

export function setIp(ipAddress) {
  return _local.set(IP_ADDRESS, ipAddress)
}

export function removeIp() {
  return _local.remove(IP_ADDRESS)
}

export function getPrivacy() {
  const res = _local.get(PRIVACY)
  if (parseInt(res) === 1) {
    return true
  } else {
    return false
  }
}

export function setPrivacy(privacy) {
  return _local.set(PRIVACY, privacy)
}

export function removePrivacy() {
  return _local.remove(PRIVACY)
}

export function getGeolocation() {
  return _local.get(GEOLOCATION)
}

export function setGeolocation(cityCode, city, adCode, district = '') {
  const geolocation = { 'cityCode': cityCode, 'city': city, 'adCode': adCode, 'district': district }
  return _local.set(GEOLOCATION, geolocation)
}

export function removeGeolocation() {
  return _local.remove(GEOLOCATION)
}

export function getChooseCity() {
  return _local.get(CHOOSE_CITY)
}

export function setChooseCity(cityCode, city, adCode = '', district = '') {
  const chooseCity = { 'cityCode': cityCode, 'city': city, 'adCode': adCode, 'district': district }
  return _local.set(CHOOSE_CITY, chooseCity)
}

export function removeChooseCity() {
  return _local.remove(CHOOSE_CITY)
}

export function getChooseCityQualify() {
  return _local.get(CHOOSE_CITY_QUALIFY)
}

export function setChooseCityQualify(cityCode, city, adCode = '', district = '') {
  const chooseCityQualify = { 'cityCode': cityCode, 'city': city, 'adCode': adCode, 'district': district }
  return _local.set(CHOOSE_CITY_QUALIFY, chooseCityQualify)
}

export function removeChooseCityQualify() {
  return _local.remove(CHOOSE_CITY_QUALIFY)
}

export function setPosition(position) {
  return _local.set(POSITION, position)
}

export function getPosition() {
  return _local.get(POSITION)
}

export function removePosition() {
  return _local.remove(POSITION)
}
//  true 允许定位权限  false 关闭权限
export function getLocationPermissions() {
  const res = _local.get(LOCATION_PERMISSIONS)
  if (parseInt(res) === 1) {
    return false
  } else {
    return true
  }
}

export function setLocationPermissions(locationPermissions) {
  return _local.set(LOCATION_PERMISSIONS, locationPermissions)
}

export function removeLocationPermissions() {
  return _local.remove(LOCATION_PERMISSIONS)
}
